﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 选项卡式页面
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            
            TabControl? tbc = this.FindName("tbc") as TabControl;
            if (tbc != null)
            {
                // 显示信息
                //MessageBox.Show("TabControl.Items.Count = " + tbc.Items.Count);

                // 创建一个TabItem
                TabItem? ti = new TabItem();
                // 设置TabItem的标题
                ti.Header = "TabItem";
                // 创建一个Grid
                Grid? g = new Grid();
                
                // g 中添加一个横向布局
                StackPanel? sp = new StackPanel();
                sp.Orientation = Orientation.Horizontal;
                sp.VerticalAlignment  = VerticalAlignment.Top;
                sp.HorizontalAlignment = HorizontalAlignment.Left;

                // sp 中添加一个标签，一个文本框，添加一个按钮
                Label? l = new Label();
                l.Content = "请输入内容：";
                TextBox? tb = new TextBox();
                tb.Name = "tb";
                tb.Text  = "请输入内容";
                tb.Width = 100;


                Button? b = new Button();
                b.Content = "确定";

                sp.Children.Add(l);
                sp.Children.Add(tb);
                sp.Children.Add(b);

                // 将sp 添加到 g 中
                g.Children.Add(sp);


                // 设置 tabitem  的 Content
                ti.Content = g;
                

                // 将  tabitem 添加到 TabControl
                tbc.Items.Add(ti);


                // 根据page1  创建一个 tabitem
                ti = new TabItem();
                ti.Header = "page2";

                //ti.Content = new Page1();  // throw new InvalidOperationException(SR.ParentOfPageMustBeWindowOrFrame);

                // 创建一个Frame
                Frame f = new Frame();
                f.Content = new Page1();
                ti.Content = f;
                tbc.Items.Add(ti);
                

            }
        }
    }
}